
class AIAssistant:
    """AI助手父类"""
    def __init__(self, id, name, type_, version, online, score):
        self.id = id
        self.name = name
        self.type = type_
        self.version = version
        self.online = online
        self.score = score

    def start(self):
        if self.online:
            print(f"助手【{self.name}】已在运行。")
        else:
            self.online = True
            print(f"✅ 助手【{self.name}】已启动。")

    def stop(self):
        if not self.online:
            print(f"助手【{self.name}】已停止。")
        else:
            self.online = False
            print(f"✅ 助手【{self.name}】已停止。")

    def assign_task(self, task):
        if self.online:
            print(f"🧠 助手【{self.name}】正在执行任务：{task}")
        else:
            print(f"❌ {self.name} 当前离线，无法执行任务。")

    def show_info(self):
        status = "🟢在线" if self.online else "🔴离线"
        print(f"ID:{self.id}, 名称:{self.name}, 类型:{self.type}, 版本:{self.version}, 状态:{status}, 能力评分:{self.score}")


class AIManager:
    """AI助手管理器"""
    def __init__(self, capacity=10):
        self.assistants = [None] * capacity
        self.count = 0

    def add_assistant(self, assistant):
        if self.count >= len(self.assistants):
            print("❌ 存储空间已满！")
            return
        self.assistants[self.count] = assistant
        self.count += 1
        print(f"✅ 助手【{assistant.name}】添加成功！")

    def show_all(self):
        print("所有AI助手列表：")
        for i in range(self.count):
            a = self.assistants[i]
            print(f"{i+1}. ID:{a.id}, 名称:{a.name}, 类型:{a.type}, 版本:{a.version}, 状态:{'在线' if a.online else '离线'}, 能力评分:{a.score}")

    def find_by_id(self, id):
        for a in self.assistants[:self.count]:
            if a.id == id:
                return a
        return None

    def query_assistant(self, id):
        a = self.find_by_id(id)
        if a:
            print(f" 查询结果:")
            a.show_info()
        else:
            print("未找到该ID的助手。")

    def modify_assistant(self, id, attr, value):
        a = self.find_by_id(id)
        if not a:
            print("未找到该助手。")
            return
        if attr == "name":
            a.name = value
        elif attr == "type":
            a.type = value
        elif attr == "version":
            a.version = value
        elif attr == "online":
            a.online = bool(int(value))
        elif attr == "score":
            a.score = int(value)
        else:
            print("属性名无效。")
            return
        print(f"助手【{id}】修改成功！")

    def delete_assistant(self, id):
        for i in range(self.count):
            if self.assistants[i].id == id:
                name = self.assistants[i].name
                for j in range(i, self.count - 1):
                    self.assistants[j] = self.assistants[j + 1]
                self.assistants[self.count - 1] = None
                self.count -= 1
                print(f"助手【{name}】已删除。")
                return
        print("未找到该助手。")

    def start_service(self, id):
        a = self.find_by_id(id)
        if a:
            a.start()
        else:
            print("未找到该助手。")

    def stop_service(self, id):
        a = self.find_by_id(id)
        if a:
            a.stop()
        else:
            print("未找到该助手。")

    def assign_task(self, id, task):
        a = self.find_by_id(id)
        if a:
            a.assign_task(task)
        else:
            print("未找到该助手。")

    def show_stats(self):
        if self.count == 0:
            print("暂无数据。")
            return
        online_count = sum(a.online for a in self.assistants[:self.count])
        offline_count = self.count - online_count
        avg_score = sum(a.score for a in self.assistants[:self.count]) / self.count
        print("\n系统统计信息：")
        print(f"总助手数: {self.count}")
        print(f"在线助手数: {online_count}")
        print(f"离线助手数: {offline_count}")
        print(f"平均能力评分: {avg_score:.2f}")


# ===============================
# 主程序入口
# ===============================
def main():
    manager = AIManager(10)

    # 初始化数据
    manager.add_assistant(AIAssistant("101", "小智", "语音助手", "v1.2", True, 85))
    manager.add_assistant(AIAssistant("102", "文小助", "文本助手", "v2.0", True, 92))
    manager.add_assistant(AIAssistant("103", "图灵", "图像助手", "v1.5", False, 88))
    manager.add_assistant(AIAssistant("104", "数小析", "数据分析助手", "v1.0", True, 79))
    manager.add_assistant(AIAssistant("105", "翻译精灵", "翻译助手", "v2.1", False, 95))

    while True:
        print("\n========== AI助手管理器 ==========")
        print("1. 查看所有AI助手列表")
        print("2. 根据ID查询助手详情")
        print("3. 添加新的AI助手")
        print("4. 根据ID修改助手信息")
        print("5. 删除AI助手（按ID）")
        print("6. 启动AI助手服务")
        print("7. 停止AI助手服务")
        print("8. 为AI助手分配任务")
        print("9. 显示系统统计信息")
        print("0. 退出系统")
        print("===================================")
        choice = input("请选择操作: ")

        if choice == "1":
            manager.show_all()
        elif choice == "2":
            id = input("请输入要查询的AI助手ID: ")
            manager.query_assistant(id)
        elif choice == "3":
            id = input("请输入ID: ")
            name = input("请输入名称: ")
            type_ = input("请输入类型: ")
            version = input("请输入版本号: ")
            online = input("是否在线？(1-是, 0-否): ") == "1"
            score = int(input("请输入能力评分(0-100): "))
            manager.add_assistant(AIAssistant(id, name, type_, version, online, score))
        elif choice == "4":
            id = input("请输入ID: ")
            print("可修改属性列表为：name,type,version,online,score")
            attr, value = input("请输入要修改的属性和值，用空格分割: ").split()
            manager.modify_assistant(id, attr, value)
        elif choice == "5":
            id = input("请输入要删除的AI助手ID: ")
            manager.delete_assistant(id)
        elif choice == "6":
            id = input("请输入要启动的AI助手ID: ")
            manager.start_service(id)
        elif choice == "7":
            id = input("请输入要停止的AI助手ID: ")
            manager.stop_service(id)
        elif choice == "8":
            id = input("请输入目标AI助手ID: ")
            task = input("请输入任务内容: ")
            manager.assign_task(id, task)
        elif choice == "9":
            manager.show_stats()
        elif choice == "0":
            print("系统已退出。")
            break
        else:
            print("❌ 无效的选项，请重新输入。")


if __name__ == "__main__":
    main()
